Modernize loop iterators to walk arrays and containes instead of independently
authorRobert Lipe <robertlipe@gpsbabel.org>
Mon, 3 Dec 2018 05:45:25 +0000 (23:45 -0600)
committerRobert Lipe <robertlipe@gpsbabel.org>
Mon, 3 Dec 2018 05:45:25 +0000 (23:45 -0600)
maintained constants.

alan.cc
an1.cc
f90g_track.cc
garmin_fit.cc
jeeps/gpsserial.h
mkshort.cc
rgbcolors.cc
shape.cc
skytraq.cc
tpo.cc
vecs.cc

diff --git a/alan.cc b/alan.cc
index 7d0c638fade0f4bb4405d8af3482331241cfe904..bc5e326ae53e1361333dd62a4a8af994f1a765da 100644 (file)
--- a/alan.cc
+++ b/alan.cc
@@ -236,8 +236,8 @@ static void swap_wpthdr(struct wpthdr* wpthdr,
   if (swap16_func != nullptr) {
     swap16_func(&wpthdr->num);
     swap16_func(&wpthdr->next);
-    for (int i=0; i<MAXWPT; i++) {
-      swap16_func(&wpthdr->idx[i]);
+    for (short &i : wpthdr->idx) {
+      swap16_func(&i);
     }
   }
 }
@@ -262,8 +262,8 @@ static void swap_rtehdr(struct rtehdr* rtehdr,
   if (swap16_func != nullptr) {
     swap16_func(&rtehdr->num);
     swap16_func(&rtehdr->next);
-    for (int i=0; i<MAXRTE; i++) {
-      swap16_func(&rtehdr->idx[i]);
+    for (short &i : rtehdr->idx) {
+      swap16_func(&i);
     }
     swap16_func(&rtehdr->rteno);
   }
@@ -277,8 +277,8 @@ static void swap_rte(struct rte* rte,
 {
   if (swap16_func != nullptr) {
     swap16_func(&rte->wptnum);
-    for (int i=0; i<MAXWPTINRTE; i++) {
-      swap16_func(&rte->wptidx[i]);
+    for (short &i : rte->wptidx) {
+      swap16_func(&i);
     }
     swap16_func(&rte->reserved);
   }
@@ -350,8 +350,8 @@ static void swap_loghdr(struct loghdr* loghdr,
     swap32_func(&(loghdr->date));
     swap32_func(&(loghdr->time));
   }
-  for (int i = 0; i<MAXTRK; i++) {
-    swap_trkhdr(&(loghdr->trkhdr[i]), swap16_func, swap32_func);
+  for (auto &i : loghdr->trkhdr) {
+    swap_trkhdr(&i, swap16_func, swap32_func);
   }
 }
 
@@ -400,8 +400,8 @@ static void trl_swap(struct trldata* trldata)
   }
 
   swap_loghdr(&(trldata->loghdr), swap16_func, swap32_func);
-  for (int i = 0; i<MAXTRK; i++) {
-    swap_trklog(&(trldata->trklog[i]), swap16_func, swap32_func);
+  for (auto &i : trldata->trklog) {
+    swap_trklog(&i, swap16_func, swap32_func);
   }
 }
 
diff --git a/an1.cc b/an1.cc
index a3d29010b53d7f78983ee5c33f138759f6b9a296..f2492bdc4b52141bfdb2e22302889c3293dd9183 100644 (file)
--- a/an1.cc
+++ b/an1.cc
@@ -130,11 +130,11 @@ static void
 ReadGuid(gbfile* f, GUID* guid)
 {
   guid->l = ReadLong(f);
-  for (int i = 0; i < 3; i++) {
-    guid->s[i] = ReadShort(f);
+  for (unsigned short &i : guid->s) {
+    i = ReadShort(f);
   }
-  for (int i = 0; i < 6; i++) {
-    guid->c[i] = ReadChar(f);
+  for (unsigned char &i : guid->c) {
+    i = ReadChar(f);
   }
 }
 
index f5c5588b6ac4ca8527965f9882c15115ed476cb7..01d70699a70a23a21c786e6072a0d5d889ff5576 100644 (file)
@@ -61,8 +61,8 @@ f90g_track_rd_init(const QString& fname)
     fatal(MYNAME ": read error");
   } else {
     // flip bits and check for valid header
-    for (int i = 0; i<HEADERRECORDSIZE; i++) {
-      header[i] ^= FLIPEDBITS;
+    for (char &i : header) {
+        i ^= FLIPEDBITS;
     }
     if (memcmp(header, VALIDHEADER, sizeof(VALIDHEADER)-1)) {
       fatal(MYNAME ": bad header");
@@ -100,8 +100,8 @@ f90g_track_read()
     if (gbfread((void*)ttRec, 1, TTRECORDSIZE, fin) != TTRECORDSIZE) {
       break;
     }
-    for (int i = 0; i<TTRECORDSIZE; i++) {
-      ttRec[i] ^= FLIPEDBITS;
+    for (char &i : ttRec) {
+        i ^= FLIPEDBITS;
     }
 
     // Pick the TT record apart and if it is good, fill in a new Waypoint
index a54592aba1441673586b49eb5de7a82a9e77d583..d11a7e5e57c39e597bad7c4e80e3f14c152dcc54 100644 (file)
@@ -110,8 +110,8 @@ fit_rd_init(const QString& fname)
 static void
 fit_rd_deinit()
 {
-  for (int local_id = 0; local_id<16; local_id++) {
-    fit_message_def* def = &fit_data.message_def[local_id];
+  for (auto &local_id : fit_data.message_def) {
+    fit_message_def* def = &local_id;
     if (def->fields) {
       xfree(def->fields);
       def->fields = nullptr;
index a9f13dae34009c79db8291826da239293f9e704a..80ddaf8e74eccf3d2a86c3e89682eac7ab0d6f51 100644 (file)
@@ -20,9 +20,8 @@
 // int32  GPS_Serial_On_NMEA(const char *port, gpsdevh **fd);
   int32  GPS_Serial_Read(gpsdevh* fd, void* ibuf, int size);
   int32  GPS_Serial_Write(gpsdevh* fd, const void* obuf, int size);
-  int32  GPS_Serial_Write_Packet(gpsdevh* fd, GPS_PPacket& packet);
-  int32  GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec);
-  void   GPS_Serial_Error(const char* hdr, ...);
-  int32  GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br);
+
+
+int32  GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br);
 
 #endif
index 86a2a061d5a2fb25c475e8512028d78314caacf1..19e62aaf3c847b5d0fde2ee60c56d8ba21b2ea7d 100644 (file)
@@ -85,8 +85,8 @@ mkshort_new_handle()
 {
   mkshort_handle_imp* h = (mkshort_handle_imp*) xcalloc(sizeof *h, 1);
 
-  for (int i = 0; i < PRIME; i++) {
-    QUEUE_INIT(&h->namelist[i]);
+  for (auto &i : h->namelist) {
+    QUEUE_INIT(&i);
   }
 
   h->whitespaceok = 1;
@@ -160,9 +160,9 @@ mkshort_del_handle(short_handle* h)
     return;
   }
 
-  for (int i = 0; i < PRIME; i++) {
+  for (auto &i : hdr->namelist) {
     queue* e, *t;
-    QUEUE_FOR_EACH(&hdr->namelist[i], e, t) {
+    QUEUE_FOR_EACH(&i, e, t) {
       uniq_shortname* s = reinterpret_cast<uniq_shortname *>(e);
 #if 0
       if (global_opts.verbose_status >= 2 && s->conflictctr) {
index bf939bb2322fe8ea568fa9486566873dc1144fdf..7db6c3dddaa49c4ea8f11a886f8917f6e980494d 100644 (file)
@@ -236,11 +236,11 @@ color_to_bbggrr(const char* opt_color)
     return color_num;
   }
 
-  for (unsigned int i = 0; i < sizeof(color_table) / sizeof(color_table[0]); i++) {
-    if (0 == case_ignore_strcmp(opt_color, color_table[i].cn)) {
-      return (color_table[i].b << 16) +
-             (color_table[i].g << 8) +
-             color_table[i].r;
+  for (auto i : color_table) {
+    if (0 == case_ignore_strcmp(opt_color, i.cn)) {
+      return (i.b << 16) +
+             (i.g << 8) +
+              i.r;
     }
   }
 
index 1f51a63529c8ffd92833e068bcb2935ecd5d7127..bdc2961dc143aaf6f1b2b98ba9e0b1fab1895f1b 100644 (file)
--- a/shape.cc
+++ b/shape.cc
@@ -300,10 +300,10 @@ my_read()
 //  } else if (nameidx == -1) {
 //      leave name as a null QString.
     } else if (nameidx == -2) {
-      for (int oidx=0; oidx<nameindices.size(); oidx++) {
+      for (int nameindice : nameindices) {
         // form a compound name from one or more dbf fields.
         QString namecomponent = DBFReadStringAttribute(
-                                  ihandledb, iShape, nameindices.at(oidx));
+                                  ihandledb, iShape, nameindice);
         if (!name.isEmpty() && !namecomponent.isEmpty()) {
           name.append(QLatin1String(" / "));
         }
index 5bbed2294e4943c591c4671f2f45395d40ea9427..a178a5d93a4e6c51930e128856d255d8047ef386 100644 (file)
@@ -1272,8 +1272,8 @@ skytraq_set_location()
   sscanf(opt_set_location, "%lf:%lf", &lat, &lng);
   le_write_double(&MSG_SET_LOCATION[1], lat);
   le_write_double(&MSG_SET_LOCATION[9], lng);
-  for (unsigned int i = 0; i<sizeof MSG_SET_LOCATION; i++) {
-    db(3, "%02x ", MSG_SET_LOCATION[i]);
+  for (unsigned char i : MSG_SET_LOCATION) {
+    db(3, "%02x ", i);
   }
   db(3, "\n");
   if (skytraq_wr_msg_verify((uint8_t*)&MSG_SET_LOCATION, sizeof(MSG_SET_LOCATION)) != res_OK) {
diff --git a/tpo.cc b/tpo.cc
index 54d04f6c185f2327c55a74d086973f0362950fd2..16a11d5b05c7802f7ea03557e6901c6d77963a35 100644 (file)
--- a/tpo.cc
+++ b/tpo.cc
@@ -522,12 +522,12 @@ static void tpo_process_tracks()
 
     // next three bytes are RGB color, fourth is unknown
     // Topo and web uses rrggbb, also need line_color.bbggrr for KML
-    for (unsigned xx = 0; xx < 3; xx++) {
+    for (unsigned char &xx : styles[ii].color) {
       int col = gbfgetc(tpo_file_in);
       if ((col < 0) || (col >255)) {
         col = 0; // assign black if out of range 0x00 to 0xff
       }
-      styles[ii].color[xx] = (uint8_t)col;
+        xx = (uint8_t)col;
     }
 
     unsigned char tmp = gbfgetc(tpo_file_in);
diff --git a/vecs.cc b/vecs.cc
index 940f2e918e521c4d6f11d01ae0100186a8671979..5f5d95f1a7a5dbf5863bb67ff270e66d3d04b3f1 100644 (file)
--- a/vecs.cc
+++ b/vecs.cc
@@ -1602,9 +1602,9 @@ disp_v1(ff_type t)
 static void
 disp_v2(ff_vecs_t* v)
 {
-  for (int i = 0; i < 3; i++) {
-    putchar((v->cap[i] & ff_cap_read) ? 'r' : '-');
-    putchar((v->cap[i] & ff_cap_write) ? 'w' : '-');
+  for (auto &i : v->cap) {
+    putchar((i & ff_cap_read) ? 'r' : '-');
+    putchar((i & ff_cap_write) ? 'w' : '-');
   }
   putchar('\t');
 }